/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/***************************************************************************
 * Name: fdbus_proxy.h
 *
 * Purpose: binding fdbus communication as proxy
 *
 * Developer:
 *   wen.gu , 2021-05-10
 *
 * TODO:
 *
 ***************************************************************************/

/******************************************************************************
 **    INCLUDES
 ******************************************************************************/
#ifndef __FDBUS_PROXY_H__
#define __FDBUS_PROXY_H__
#include "common_base/fdbus.h"
#include "proxy_requester.h"

/******************************************************************************
 **    MACROS
 ******************************************************************************/


/******************************************************************************
 **    TYPE DEFINITIONS
 ******************************************************************************/



/******************************************************************************
 **    CLASSES/FUNCTIONS DEFINITIONS
 ******************************************************************************/
class FDBusProxy: public ProxyRequester, public CBaseClient
{
public:
    FDBusProxy(const std::string& srv_name);
    virtual ~FDBusProxy();
public:
    /** connect to service */

    /**
     * start to connect to service and wait unitil timeout or successfull connect to service
     */
    ErrorCode Connect(int32_t timeout_ms = CONNECT_WAIT_INFINITE) override;

    /**
     * try to connect to service, and return result immediately.
    */
    ErrorCode TryConnect() override;

    /**
     * start to connect to service, the result will return by callback  'handler'
     */
    ErrorCode ConnectAsync(ConnectStatusHandler handler) override;

    /** disconnect from service*/
    ErrorCode Disconnect() override;
public:
    DeserializerPtr GetDeserializer(Message::PayloadPtr payload) override;
    SerializerPtr GetSerializer() override;
    MessagePtr MakeMessage(MessageType type) override;
    /** message id or session id */
    bool RegisterReceiveHandler(MessageType type, MessageId id, ProxyReceiveHandler handler) override;
    bool UnregisterReceiveHandler(MessageType type, MessageId id) override;
    bool Send(MessagePtr msg) override;

public:
    bool Subscribe(MessageId id) override;
    bool Unsubscribe(MessageId id) override;
    bool UnSubscribeAll() override;
    bool SubscribeGroup(GroupId group_id) override; //this could be call EventBase::group_id() to get the group id
    bool UnSubscribeGroup(GroupId group_id) override;
protected:
    bool RegisterReplyHandler(SessionId id, ProxyReceiveHandler handler) override;    
private:

};

#endif /** !__FDBUS_PROXY_H__ */

